# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon

from absl import app, flags

from coin.support.account_control.util import calculate_fee_rate
from coin.proto.coin_request_pb2 import AccountRequestProto
from coin.proto.account_control_pb2 import FeeRateRequest
from google.protobuf.json_format import MessageToJson

FLAGS = flags.FLAGS

flags.DEFINE_string('market_type', None, 'Market type.')

flags.DEFINE_string('exchange', None, 'Exchange.')

flags.DEFINE_string('owner', None, 'Owner.')

flags.DEFINE_string('symbol', None, 'Symbol.')


def main(_):
  market_type = FLAGS.market_type
  exchange = FLAGS.exchange
  owner = FLAGS.owner
  symbol = FLAGS.symbol
  assert market_type, 'market_type is not set.'
  assert exchange, 'exchange is not set.'
  assert owner, 'owner is not set.'
  assert symbol, 'symbol is not set.'

  target = AccountRequestProto(market_type=market_type, exchange=exchange, owner=owner)
  fee_rate_request = FeeRateRequest(target=target, symbol=symbol)
  fee_rate_response = calculate_fee_rate(fee_rate_request)

  print(MessageToJson(fee_rate_response, preserving_proto_field_name=True))


if __name__ == '__main__':
  app.run(main)
